[WPF Datagrid] Binding to a List<>

Posted by Tr?n Qu?c Bình on Stack Overflow See other posts from Stack Overflow or by Tr?n Qu?c Bình
Published on 2010-04-25T04:17:53Z Indexed on 2010/04/25 4:23 UTC
Read the original article Hit count: 493

Filed under:
|
|
|

I have a datagrid like this:

<dg:DataGrid Name="dg" AutoGenerateColumns="False" CanUserDeleteRows="True">
                    <dg:DataGrid.Columns>
                        <dg:DataGridTextColumn Header="Product Code" x:Name="columnProductCode" Binding="{Binding Path=Product.ProductCode}" IsReadOnly="True" ></dg:DataGridTextColumn>
                        <dg:DataGridTextColumn Header="Product Name" x:Name="columnProductName" Binding="{Binding Path=Product.Name}" IsReadOnly="True" ></dg:DataGridTextColumn>
                        <dg:DataGridTextColumn Header="ProductMeasure" x:Name="columnDonViTinh" Binding="{Binding Path=Product.Measure IsReadOnly="True"></dg:DataGridTextColumn>
                        <dg:DataGridTextColumn Header="Quantity" x:Name="ColumnQuantity" Binding="{Binding Path=Quantity IsReadOnly="False"></dg:DataGridTextColumn>
                    </dg:DataGrid.Columns>
</dg:DataGrid>

In the behind code, I have a struct like this:

private struct ProductDetail
        {

            public TProduct Product { get; set ; } // TProduct is a class provied by a web service
            public int Quantity { get; set; }
        }

and a List like this:

        private IList<ProductDetail> bs = new List<ProductDetail>();

I had tried to fill data to "bs". And binding like this:

this.dg.ItemsSource = this.bs;

Everything is ok. I can insert a new row, delete row, but when I try to modified the column Quantity then click on the header of the datagrid (to resort) --> the Quantity column change to it is before.

How can I fix this problem. Thanks advanced.

© Stack Overflow or respective owner

Related posts about wpf

Related posts about datagrid